package com.cxlin.base.ext

import android.content.Context
import android.os.Build
import android.view.View

/**
 *
 * @Author: chenxunlin
 * @Date: 2024/4/27 9:30
 */

fun fromN() = fromSpecificVersion(Build.VERSION_CODES.N)
fun fromSpecificVersion(version: Int): Boolean = Build.VERSION.SDK_INT >= version

fun Context.dp2px(dp: Int): Int {
    val scale = resources.displayMetrics.density
    return (dp * scale + 0.5f).toInt()
}

fun Context.px2dp(px: Int): Int {
    val scale = resources.displayMetrics.density
    return (px / scale + 0.5f).toInt()
}

fun View.dp2px(dp: Int): Int {
    val scale = resources.displayMetrics.density
    return (dp * scale + 0.5f).toInt()
}